
package cn.ekgc.scalademo1

object HelloWorld  extends App {
  // scala  方法调用可以不用点 用空格  参数参数传递可以不用小括号 用空格
  //1 to 10 foreach println //能看懂不

  //1.to(10).foreach(i => println(i))

//  for(i <- 1 to 10 ; if i % 2 == 0 ; if i <= 5){
//    println(i)
//  }

  //1 to 10 filter(_ <= 5) filter(_%2==0) foreach println

  //yield
    //定义一个数组或者集合
   // var nn = for(i <- 1 to 10 ; if i % 2 == 0 ; if i <= 5) yield i
    /*{
      // 把符合条件的数据加入到数组或集合中 println(i)
    }*/

  //nn foreach println

  //nn foreach println

  //var num = 6

  // 类似shell

  /*for (i <- 0 to 6){
    println(s"$i + ${num - i} = $num")
  }*/


   //
   //0 to num map{ i => s"$i + ${num - i} = $num" } foreach println

  //var dd = Array.range(1,10,2)

  //dd map{i => i*i} foreach println

 // val yuanzu = (12,"abc",3.5,99,77)
//  println(yuanzu.getClass)
//
//  println(yuanzu._2)
//
  //val(a,_,_,_,c) = yuanzu
 // println(a)
//  // println(b)
 // println(c)

  //yuanzu.productIterator.foreach(println)

  //var a = scala.collection.mutable.ListBuffer(3,5,8)
  //a +=
  //a += 77

  //a(1)=7
 //a foreach println
 //var c = List[Char]('a', 'b', 'c')
  //var x = 'x' +: c    // (x, a, b, c)

 //var y = c :+ 'x'   // (a, b, c, x)
  //println(y)
  //import scala.collection.mutable._
  //var lb = ListBuffer[Int](1, 2, 3, 4)
//  lb.+=(100)    //1, 2, 3, 4, 100
 // lb.+=(21, 33,44,55,66)// ...args
  //println(lb)
  //88 +=: lb   //88, 1, 2, 3, 4, 100, 21, 33
  //println(lb)
  //lb ++= List(77, 66)
 // println(lb)

  //var l = List[Int](2, 3, 4, 6, 8, 9, 11,20)
//  var x = l grouped 3   //等价l.grouped(3)
//  while(x.hasNext){
//    println(x.next())
//  }

//  x.next()    //(2, 3, 4)
//  x.next()   //(6, 8, 9)
  //var y = l sliding 2
 // y foreach println
//  y.next()  // (2, 3)
//  y.next()  // (3, 4)


//  var a1 = Array[Int](1, 2, 3,3, 4)
//  var a2 = Array[Int](100, 200, 300, 400)
//  var a = List.concat(a1, a2)//Array->List
//  var a3=a1 ++ a2  //Arrays->Array

//  a(3) = 333    //Error
 // a3(3)=333    //OK
  //println(a3.toList)
   //var b = Array(333, "33333",'3', false )
//  var c = List.concat(a, b)
  //val x = a.filter( _ %2 != 0 )
  //println(x)
   //val y = a.reverse
  //println(y)
  //var m = a.groupBy(t => t%2 == 0)
  //println(m)
  // var n = a.slice(2, 4)
  //println(n)
   //a.sorted   //1, 2, 3, 4, 100, 200, 300, 400
   //import Ordering.Int.
  // implicit val r = Ordering.Int.reverse
  //a.sorted
  //println(a.sorted)
//  a.sorted( Ordering.Int.reverse )
 // println(a.sortWith( _ > _))
//  a.sortBy( x => x )   //升序
//  a.sortBy( x => x*(-1) )   //降序

  val a = Array("a" -> 4,"b" -> 3, "c" -> 2)
  println(a.toList)

  println(a.sortBy(_._2).toList)



}
